#!/usr/bin/python

from math import sqrt
from math import floor

def getp(n):
    '''get the sequence to represent the continued fraction of the square root of n.
    return value is a tuple, the first element is list of the head, the second element is the list of the period of expansion'''
    al = []        #the a0,a1,a2 list
    bl = []        #the b0,b1,b2 list
    cl = []        #the c0,c1,c2 list
    a = int(floor(sqrt(n)))
    if a**2 == n:
        return ([a], [])
    b = 1
    c = a
    al.append(a)
    bl.append(b)
    cl.append(c)
    while True:
        #get the next iteration
        b= (n - c*c)/b
        a = 0
        while True:
            if c < 0 and (c-b)**2>n:
                c = -c
                break
            a += 1
            c -= b
        #repeated?
        if b in bl and c in cl:
           bi = bl.index(b)
           ci = cl.index(c)
           if bi == ci:
               return (al[:bi+1],al[bi+1:] + [a])
        al.append(a)
        bl.append(b)
        cl.append(c)
            
    
def main():
    print sum([len(getp(n)[1])%2 and 1 or 0 for n in range(1,10001)])
        
if __name__ == '__main__':
    main()
    
